package com.gangan.controller.web;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gangan.controller.common.BaseController;
import com.gangan.model.Disease;
import com.gangan.model.Doctor;
import com.gangan.service.IDoctorService;
import com.gangan.tools.MessageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-09-04
 */
@Api(value = "/doctor",description = "*医生模块控制层")
@RestController
@RequestMapping("/doctor")
public class DoctorController extends BaseController {

    @Autowired(required = true)
    IDoctorService doctorService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "医生列表", notes = "根据相关条件查询列表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "name", dataType = "String", required = false, value = "医生名字或者关键字", defaultValue = "吴医生")
    })
    public MessageBean list(Page page, String name) {
        return resultSuccess(doctorService.pageAndLikeName(page, name));
    }

    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @ApiOperation(value = "移除医生", notes = "根据自增主键移除数据")
    public MessageBean del(Integer id) {
        return resultSuccess(doctorService.removeById(id));
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "新增医生", notes = "将提交的数据保存到数据库")
    public MessageBean add(Doctor add) {
        return resultSuccess(doctorService.save(add));
    }

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation(value = "编辑医生", notes = "根据主键修改数据")
    public MessageBean edit(Doctor edit) {
        return resultSuccess(doctorService.updateById(edit));
    }


    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    @ApiOperation(value = "查看医生详细信息", notes = "根据主键修改数据")
    public MessageBean getDoctorById(Integer id) {
        return resultSuccess(doctorService.getById(id));
    }


    @RequestMapping(value = "/suspension", method = RequestMethod.POST)
    @ApiOperation(value = "医生管理", notes = "停职医生")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "isSuspension", dataType = "Boolean", required = true, value = "是否停职 true:停职 false:在职", defaultValue = "false")
    })
    public MessageBean edit(@RequestParam(value = "idList") List<Integer> idList, Boolean isSuspension) {
        if (CollectionUtils.isEmpty(idList)) {
            return resultSuccess();
        }
        try {
            for (Integer id :idList) {
                doctorService.isSuspension(id, isSuspension);
            }
        } catch (Exception e) {
            return resultFailed();
        }
        return resultSuccess();
    }
}
